---
category: String
created: '2022-08-21'
title: Decode HTML entities
---

**JavaScript version**

```js decodeHtmlEntities.js
const decodeHtmlEntities = (str) => str.replace(/&#(\w+)(^\w|;)?/g, (_, dec) => String.fromCharCode(dec));
```

**TypeScript version**

```ts decodeHtmlEntities.ts
const decodeHtmlEntities = (str: string): string =>
    str.replace(/&#(\w+)(^\w|;)?/g, (_, dec) => String.fromCharCode(dec));
```
